<template>
  <div class="main coupon-edit">
    <section>
      <el-form ref="form" size="medium" label-width="150px" :rules="commonRules" :model="configData">
        <div class="block-content">
          <el-form-item label="等级名称:" prop="levelName" :rules="commonRules.notNullRule">
            <el-input v-model="configData.levelName" maxlength="6" clearable></el-input>
          </el-form-item>
          <el-form-item label="等级:">
            {{configData.levelId}}
          </el-form-item>
          <el-form-item label="升级条件:">
            {{configData.upgradeCondition}}
          </el-form-item>
          <el-form-item label="奖金:" prop="commissionRate" :rules="commonRules.percentRule">
              推荐奖
              <el-input placeholder="每箱金额百分比" style="width:200px" v-model="configData.commissionRate" clearable></el-input>
              %
          </el-form-item>
        </div>
        <el-form-item label="" style="margin-top:20px;">
          <el-button size="medium" :loading="btnLoading" @click="save">保存</el-button>
          <el-button type="info" size="medium" plain @click="$router.push({ name: 'boxTransLevel' })">取消</el-button>
        </el-form-item>
      </el-form>
    </section>
  </div>
</template>
<script>
import draggable from 'vuedraggable'
import Tinymce from '@/components/Tinymce'
export default {
  name: 'NewLevelEdit',
  components: {
    Tinymce,
    draggable
  },
  data() {
    return {
      configData: {
        commissionConfigId: '',
        commissionRate: '',
        levelId: '',
        levelName: '',
        upgradeCondition: ''
      },
      btnLoading: false,

    }
  },
  // mounted() {},
  created() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      this.request({
            url: '/bsnl-product/box/privilege-commission-config/get',
            method: 'get',
            params: { commissionConfigId : this.$route.params.id}
          }).then((res) => {
            if (res.status === 200) {
              this.configData = res.data
            }
          }).catch((err) => {
            this.btnLoading = false
          })
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.request({
            url: '/bsnl-product/box/privilege-commission-config/update',
            method: 'post',
            data: this.configData
          }).then((res) => {
            if (res.status === 200) {
              this.$message.success(res.message)
              this.btnLoading = false
              this.$router.push({ name: 'boxTransLevel' })
            }
          }).catch((err) => {
            this.btnLoading = false
          })
        }
      })
    },
  }
}
</script>
<style lang="scss">
    
</style>
